package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.Bean.Result;
import com.yc.yyds.dao.ArrangeDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SaveArrangeServlet", value = "/SaveArrangeServlet.s")
public class SaveArrangeServlet extends HttpServlet {
    ArrangeDao dao=new ArrangeDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cinemaid = request.getParameter("cinemaid");
        String movieid = request.getParameter("movieid");
        String starttime = request.getParameter("starttime");
        String endtime = request.getParameter("endtime");
        String sell = request.getParameter("sell");
        String remainseats = request.getParameter("remainseats");
        System.out.println("starttime = " + starttime);
        System.out.println("endtime = " + endtime);
        String ppjhid = request.getParameter("ppjhid");

//        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//
//        String format = sf.format(starttime);
//        String format1=sf.format(endtime);
//        Date parse = null;
//        Date parse1=null;
//
//        try {
//            parse = (Date) sf.parsformat1);
////        } catch (ParseException e) {e(format);
//            parse1= (Date) sf.parse(
//            e.printStackTrace();
//        }
//        System.out.println("1:"+starttime);
//        System.out.println("2:"+parse);
        Result result;
        try{
            if(ppjhid!=null){
                dao.modify(ppjhid,cinemaid,movieid,starttime ,endtime,sell,remainseats);
            }else{
                dao.create(cinemaid,movieid,starttime ,endtime,sell,remainseats);
            }
            result=new Result(1,"安排成功",null);
        }catch (Exception e){
            e.printStackTrace();
            result=new Result(0,"安排失败",null);
        }
        String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
